package kr.saeildamil.androidstudy.ch19;

import kr.saeildamil.androiddforstudy.R;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.Toast;

public class JobSchedulePost extends Activity {
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.ch19_jobscheduletest);
		
		findViewById(R.id.ch19_jobscheduletest_uploadbtn).setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				new AlertDialog.Builder(JobSchedulePost.this)
				.setTitle("Question")
				.setMessage("Do you want to upload this?")
				.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
					
					@Override
					public void onClick(DialogInterface dialog, int which) {
					//	mHandler.sendEmptyMessageDelayed(0,10);
					/*	mHandler.postDelayed(new Runnable(){
							@Override
							public void run() {
								mUpload();
							}
						}, 10); */
						Button btn = (Button) findViewById(R.id.ch19_jobscheduletest_uploadbtn);
						btn.postDelayed(new Runnable() {
							
							@Override
							public void run() {
								mUpload();
							}
						}, 10);
					}
				})
				.setNegativeButton("No", null)
				.show();
			}
		});
	}
	
	private void mUpload() {
		for(int i = 0; i<20; i++){
			try {
				Thread.sleep(500);
			} catch (InterruptedException e) {}
		}
		Toast.makeText(this, "Completed", Toast.LENGTH_SHORT).show();
	}
}
